package com.iss.umservice.common;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.servlet.tags.RequestContextAwareTag;

import com.iss.iframework.security.OperatorUserEntry;
import com.iss.umservice.manager.AccountManager;

/**
 * @author luzi
 *
 */
public class AuthTag extends RequestContextAwareTag {
	private String[] userTypes;
	@Autowired
    private AccountManager accountManager;

	public void setUserType(String userTypes) {
		this.userTypes = userTypes.split(",");
	}
	
	public int doStartTagInternal() {
		OperatorUserEntry userEntry = (OperatorUserEntry) pageContext.getSession()
				.getAttribute("curUser");
		accountManager = (AccountManager)getRequestContext().getWebApplicationContext().getBean("accountManager");  
		String userType= accountManager.queryUserType(userEntry.userIdentifier());
		//
		for(String t:userTypes){
			if(t.equals(userType)){
				return EVAL_BODY_INCLUDE;
			}
		}
		return SKIP_BODY;
	}
}
